# def webUV():
#     #从日志中获取地址信息
#     file_log = r"D:\pythonpro\test2\access_log"
#     data01 = []
#     with open(file_log, mode="r") as fobj:
#      for line in fobj:
#        data = line.split()[0]
#        if data != "::1":
#         data01.append(data)
#      for ip in set(data01):
#         print("客户端访问地址位:%s  访问次数位:%s" % (ip, data01.count(ip)))
#
# if __name__ == '__main__':
#     webUV()


# 通过正则表达式来统计客户端访问次数
import re
def webUV():
    #从日志中获取地址信息
    file_log = r"D:\pythonpro\test2\access_log"
    data02 = []
    ip_regex = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
    with open(file_log, mode="r") as fobj:
      for line in fobj:
        data = re.search(ip_regex, line)
        if data:
           data01 = data.group()
           data02.append(data01)
    for ip in set(data02):
        print("客户端访问地址位:%s  访问次数位:%s" % (ip, data02.count(ip)))

if __name__ == '__main__':
  webUV()
